<?php
require_once('simpletest/autorun.php');
require_once('requests.php');

class TestOfSessionClass extends UnitTestCase{
	function testCreateSession()
	{
		$ses = array("session" => array("ip" => "192.184.21.21"));
		$a = json_encode($ses);
		//var_dump($a);
		$session = POST("http://127.0.0.1/project-advertise-on-car/sessions/session?format=json", $a);
		//echo($session);
		//$session = GET("http://127.0.0.1/project-advertise-on-car/sessions/session");
		
		
		$b = json_decode($session);
		//var_dump($b);
		$this->assertEqual(strlen($b->session->content), 32);
		
		$session2 = GET("http://127.0.0.1/project-advertise-on-car/sessions/session/bycontent/" . $b->session->content . "?format=json");
		
		$c = json_decode($session2);
		$this->assertEqual($c->session->content, $b->session->content);
	}
	
	function testCreateSessionWithoutIP()
	{
		$ses = array("session" => array("ip" => ""));
		$a = json_encode($ses);
		//var_dump($a);
		$session = POST("http://127.0.0.1/project-advertise-on-car/sessions/session?format=json", $a);
		echo($session);
		//$session = GET("http://127.0.0.1/project-advertise-on-car/sessions/session");
		echo $session;

		//var_dump($b);
		$this->assertEqual(strlen($session), 0);
	}
}
?>